<?php
require_once("Elements.php");

/**
 * This form is used when user not be invited want to join invitation.
 * If user has en entry in db, then just have a add button, otherwise,
 * prompt a email box to let user fill in email.
 *  
 * @author james
 *
 */
class ApprovalForm extends Zend_Form {
	private $user;
	private $invitation_id;
	
	/**
	 * Constructor.
	 * 
	 * @param $invited_user_id
	 * @param $invitation_id
	 */
	public function ApprovalForm($user, $invitation_id) {
		$this->invitation_id = $invitation_id;
		$this->user = $user;
		$this->__construct();
	}
	
	/**
     * Initialization.
	 */
	public function init() {
		$languageFile = Zend_Registry::get('languageFile');
        $translate = new Zend_Translate('array',$languageFile, 'zh_CN');
        $this->setTranslator($translate);
        $this->setName('approvalForm');
		
		$this->setMethod('post');
		$elements = new Elements();
		
		$element = new Zend_Form_Element_Hidden('invitation_id');
		$element->setValue($this->invitation_id);
		$this->addElement($element);
		
		if (!isset($this->user)) {
			$element = $elements->getEmailTextField(null);
			$this->addElement($element);
		} else {
			$element = new Zend_Form_Element_Hidden('user_id');
			$element->setValue($this->user->id);
			$this->addElement($element);
		}
		
		$submit = $this->createElement('submit', 'submit');
		$submit->setName('Join');	
		$this->addElement($submit);
	}
	
}
?>